//
//  CSBActiveXQSweeping.swift
//  CurSodoboAer
//
//  Created by CurSodoboAer on 2024/11/5.
//

import UIKit
import JDStatusBarNotification

class CSBActiveXQSweeping: UIViewController {
    private let csbBackComButton = UIButton.init()
    private let csbAlertComButton = UIButton.init()
    private let bottometCoverView = UIView.init()
    private let uderNamerCSB = UILabel()
    
    
    private let csbBottonJoinComButton = UIButton.init()
    var activeDataCSB:Dictionary<String,String>
    init(qugaoshCSB:[Int]?,activeDataCSB: Dictionary<String, String>) {
        if qugaoshCSB?.first ?? 0 > 0 {
            self.activeDataCSB = activeDataCSB
        }else{
            self.activeDataCSB = activeDataCSB
        }
        
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        bottometCoverView.layer.cornerRadius = 30
        bottometCoverView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        uderNamerCSB.textColor = .white
        uderNamerCSB.textAlignment = .left
        uderNamerCSB.font = UIFont(name: "Helvetica Bold", size:22)
        
        uderNamerCSB.text = activeDataCSB["csbActiveName"] ?? ""
        
        csbBottonJoinComButton.setImage(UIImage.init(named: "joinnowbg"), for: .normal)
        
        
        view.backgroundColor = UIColor(red: 0.64, green: 0.41, blue: 0.98, alpha: 1)
        view.addSubview(mainScreCSB)
        mainScreCSB.backgroundColor = .clear
        
        
        csbBackComButton.setImage(UIImage.init(named: "csb_back"), for: .normal)
        csbBackComButton.addTarget(self, action: #selector(csbButtonClick), for: .touchUpInside)
        csbAlertComButton.setImage(UIImage.init(named: "active_report"), for: .normal)
        csbAlertComButton.addTarget(self, action: #selector(csbrepotrtClick), for: .touchUpInside)
        
        csbBottonJoinComButton.addTarget(self, action: #selector(csbrjoinClick), for: .touchUpInside)
       
        
        
        
        addAotherCSB()
        
        addCenterINfoVire()
    }
    
    private func addAotherCSB()  {
        let topCovrer = UIImageView(image: UIImage.init(named: activeDataCSB["csbActiveCover"] ?? ""))
        topCovrer.contentMode = .scaleAspectFill
        view.addSubview(topCovrer)
        view.addSubview(csbBackComButton)
        view.addSubview(csbAlertComButton)
        topCovrer.addSubview(uderNamerCSB)
        view.addSubview(bottometCoverView)
        bottometCoverView.addSubview(mainScreCSB)
        view.addSubview(csbBottonJoinComButton)
        
       
        topCovrer.snp.makeConstraints { make in
            make.leading.trailing.top.equalToSuperview()
            make.height.equalTo(280.xQQ)
        }
        let stattusBarHeight = UIApplication.shared.statusBarFrame.height
        csbBackComButton.snp.makeConstraints { make in
            make.leading.equalToSuperview().inset(12.xQQ)
            make.width.equalTo(24)
            make.height.equalTo(22)
            make.top.equalToSuperview().offset(stattusBarHeight + 15)
        }
        
        csbAlertComButton.snp.makeConstraints { make in
            make.width.height.equalTo(24)
            make.trailing.equalToSuperview().inset(12.xQQ)
            make.centerY.equalTo(csbBackComButton)
        }
        
        uderNamerCSB.snp.makeConstraints { make in
            make.leading.trailing.equalToSuperview().inset(14.xQQ)
            make.bottom.equalToSuperview()
        }
        
        
        bottometCoverView.backgroundColor = UIColor(red: 0.64, green: 0.41, blue: 0.98, alpha: 1)
        bottometCoverView.snp.makeConstraints { make in
            make.leading.trailing.bottom.equalToSuperview()
            make.top.equalTo(uderNamerCSB.snp.bottom).offset(16.xQQ)
        }
        mainScreCSB.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        csbBottonJoinComButton.snp.makeConstraints { make in
            make.width.equalTo(341.xQQ)
            make.height.equalTo(56.xQQ)
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-52)
        }
        
        
    }
    
    
    private func addCenterINfoVire()  {
        let centertCover = UIView.init()
        centertCover.backgroundColor = UIColor(red: 0.07, green: 0.07, blue: 0.07, alpha: 1)
        centertCover.layer.cornerRadius = 28.xQQ
        centertCover.layer.masksToBounds = true
        self.mainScreCSB.addSubview(centertCover)
        centertCover.snp.makeConstraints { make in
            make.leading.trailing.equalToSuperview().inset(12.xQQ)
            make.width.equalTo(UIScreen.main.bounds.width - 24.xQQ)
            make.top.equalToSuperview().offset(16.xQQ)
            make.height.equalTo(240.xQQ)
        }
        
        let dateday = UIImageView.init(image: UIImage.init(named: "active_date"))
        let durday = UIImageView.init(image: UIImage.init(named: "active_timer"))
        let localday = UIImageView.init(image: UIImage.init(named: "active_location"))
        let activeday = UIImageView.init(image: UIImage.init(named: "active_persion"))
        
        let datelvbl = UILabel.init()
        datelvbl.textColor = .white
        datelvbl.textAlignment = .left
        datelvbl.font = UIFont(name: "Helvetica Bold", size:16.xQQ)
        datelvbl.text = activeDataCSB["csbActiveTimeDate"] ?? ""
        
        
        let durlvbl = UILabel.init()
        durlvbl.textColor = .white
        durlvbl.textAlignment = .left
        durlvbl.font = UIFont(name: "Helvetica Bold", size:16.xQQ)
        durlvbl.text = activeDataCSB["csbActiveTimeClock"] ?? ""
        
        
        let locallvbl = UILabel.init()
        locallvbl.textColor = .white
        locallvbl.textAlignment = .left
        locallvbl.font = UIFont(name: "Helvetica Bold", size:16.xQQ)
        locallvbl.text = activeDataCSB["csbActivePlace"] ?? ""
        locallvbl.numberOfLines = 0
        let titlrlvbl = UILabel.init()
        titlrlvbl.textColor = .white
        titlrlvbl.textAlignment = .left
        titlrlvbl.font = UIFont(name: "Futura Medium", size: 22)
        titlrlvbl.text = "Introduction"
        
        
        let alldestailrlvbl = UILabel.init()
        alldestailrlvbl.textColor = .white
        alldestailrlvbl.textAlignment = .left
        alldestailrlvbl.font = UIFont(name: "Futura Medium", size: 15)
        alldestailrlvbl.text = activeDataCSB["csbActivePref"] ?? ""
        alldestailrlvbl.numberOfLines = 0
        
        
        

        
        centertCover.addSubview(dateday)
        centertCover.addSubview(durday)
        centertCover.addSubview(localday)
        centertCover.addSubview(activeday)
        
        centertCover.addSubview(datelvbl)
        centertCover.addSubview(durlvbl)
        centertCover.addSubview(locallvbl)
        
        
        self.mainScreCSB.addSubview(titlrlvbl)
        self.mainScreCSB.addSubview(alldestailrlvbl)
        
        dateday.snp.makeConstraints { make in
            make.width.height.equalTo(30.xQQ)
            make.leading.top.equalToSuperview().inset(20.xQQ)
        }
        datelvbl.snp.makeConstraints { make in
            make.centerY.equalTo(dateday)
            make.leading.equalTo(dateday.snp.trailing).offset(12)
        }
        
        
        durday.snp.makeConstraints { make in
            make.width.height.equalTo(30.xQQ)
            make.leading.equalToSuperview().inset(20.xQQ)
            make.top.equalTo(dateday.snp.bottom).offset(26.xQQ)
        }
        durlvbl.snp.makeConstraints { make in
            make.centerY.equalTo(durday)
            make.leading.equalTo(durday.snp.trailing).offset(12)
        }
        
        localday.snp.makeConstraints { make in
            make.width.height.equalTo(30.xQQ)
            make.leading.equalToSuperview().inset(20.xQQ)
            make.top.equalTo(durday.snp.bottom).offset(26.xQQ)
        }
        locallvbl.snp.makeConstraints { make in
            make.centerY.equalTo(localday)
            make.leading.equalTo(localday.snp.trailing).offset(12)
        }
        activeday.snp.makeConstraints { make in
            make.width.height.equalTo(30.xQQ)
            make.leading.equalToSuperview().inset(20.xQQ)
            make.top.equalTo(localday.snp.bottom).offset(26.xQQ)
        }
        
        
        
        let imgnajelisr = (activeDataCSB["csbJoinHeaer"] ?? "").components(separatedBy: "*")
        for (kk,item )in imgnajelisr.enumerated() {
            let hedCSB = UIImageView(image: UIImage.init(named: item))
            hedCSB.layer.cornerRadius = 18.xQQ
            hedCSB.layer.masksToBounds = true
            
            hedCSB.contentMode = .scaleAspectFill
            centertCover.addSubview(hedCSB)
            hedCSB.snp.makeConstraints { make in
                make.leading.equalTo(activeday.snp.trailing).offset(12 + 20*kk )
                make.centerY.equalTo(activeday)
                make.width.height.equalTo(36.xQQ)
            }
        }
        
        
        titlrlvbl.snp.makeConstraints { make in
            make.leading.equalToSuperview().inset(14.xQQ)
            make.top.equalTo(centertCover.snp.bottom).offset(24.xQQ)
        }
        
        
        alldestailrlvbl.snp.makeConstraints { make in
            make.leading.trailing.equalToSuperview().inset(14.xQQ)
            make.top.equalTo(titlrlvbl.snp.bottom).offset(12)
            make.bottom.equalToSuperview().offset(-80 - 56)
        }
    }
    
    @objc func csbButtonClick()  {
        self.navigationController?.popViewController(animated: true)
    }

    @objc func csbrepotrtClick()  {
        self.navigationController?.pushViewController(CSBAIrAlertSweeping.init(), animated: true)
    }
    
    @objc func csbrjoinClick()  {
        NotificationPresenter.shared.present("")
        NotificationPresenter.shared.displayActivityIndicator(true)
        
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2, execute: DispatchWorkItem(block: {
            NotificationPresenter.shared.present("Your request is currently under review, please be patient.....", includedStyle: .success)
        }))
    }
    
    private let mainScreCSB = UIScrollView.init()
    
}
